import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";

const routes = [
  {
    path: "/",
    name: "Home",
    redirect: "/dashboard",
    component: Home,
    children: [
      {
        path: "/dashboard",
        name: "dashboard",
        meta: { title: "系统首页" },
        component: () => import("../views/Dashboard.vue"),
      },
      {
        path: "/consumeRank",
        name: "consumeRank",
        meta: { title: "后台团队配置" },
        component: () => import("../views/consumeRank"),
      },
      {
        path: "/greenRank",
        name: "greenRank",
        meta: { title: "后台团队配置" },
        component: () => import("../views/greenRank"),
      },
      {
        path: "/user",
        name: "user",
        meta: { title: "个人中心" },
        component: () => import("../views/user/index"),
      },
      //用户管理
      {
        path: "/userControl",
        name: "userControl",
        meta: { title: "用户管理" },
        component: () => import("../views/user/userControl"),
      },
      {
        path: "/userAddress",
        name: "userAddress",
        meta: { title: "用户地址管理" },
        component: () => import("../views/user/address"),
      },
      {
        path: "/userAutonym",
        name: "userAutonym",
        meta: { title: "用户实名认证信息" },
        component: () => import("../views/user/autonym"),
      },
      {
        path: "/powerAudit",
        name: "powerAudit",
        meta: { title: "商家审核" },
        component: () => import("../views/user/powerAudit"),
      },
      {
        path: "/authentication",
        name: "authentication",
        meta: { title: "实名认证审核" },
        component: () => import("../views/user/authentication"),
      },
      {
        path: "/store",
        name: "store",
        meta: { title: "门店管理" },
        component: () => import("../views/store/store"),
      },
      {
        path: "/storeClass",
        name: "storeClass",
        meta: { title: "门店分类" },
        component: () => import("../views/store/class"),
      },
      {
        path: "/storeOrder",
        name: "storeOrder",
        meta: { title: "商家订单管理" },
        component: () => import("../views/store/order"),
      },
      {
        path: "/storeConfig",
        name: "storeConfig",
        meta: { title: "商户配置" },
        component: () => import("../views/store/config"),
      },
      {
        path: "/subscribersAgent",
        name: "subscribersAgent",
        meta: { title: "后台获取用户代理" },
        component: () => import("../views/user/subscribersAgent"),
      },


      {
        path: "/usersMemberConfig",
        name: "usersMemberConfig",
        meta: { title: "VIP等级配置" },
        component: () => import("../views/level/usersMemberConfig"),
      },
      {
        path: "/usersTeamConfig",
        name: "usersTeamConfig",
        meta: { title: "团队等级配置" },
        component: () => import("../views/level/usersTeamConfig"),
      },
      {
        path: "/usersTierConfig",
        name: "usersTierConfig",
        meta: { title: "合伙人等级配置" },
        component: () => import("../views/level/usersTierConfig"),
      },


      //系统管理
      {
        path: "/advertPic",
        name: "advertPic",
        meta: { title: "广告图片" },
        component: () => import("../views/system/advertPic"),
      },
      {
        path: "/tripartiteLink",
        name: "tripartiteLink",
        meta: { title: "三方链接" },
        component: () => import("../views/system/tripartiteLink"),
      },
      {
        path: "/dayTask",
        name: "dayTask",
        meta: { title: "用户每日任务" },
        component: () => import("../views/system/dayTask"),
      },
      {
        path: "/mobileCode",
        name: "mobileCode",
        meta: { title: "用户手机验证码" },
        component: () => import("../views/system/mobileCode"),
      },
      {
        path: "/usersMessage",
        name: "usersMessage",
        meta: { title: "公告信息中心" },
        component: () => import("../views/system/usersMessage"),
      },
      {
        path: "/sysConfig",
        name: "sysConfig",
        meta: { title: "全局配置" },
        component: () => import("../views/system/sysConfig"),
      },
      {
        path: "/freight",
        name: "freight",
        meta: { title: "运费模板" },
        component: () => import("../views/freight/freight"),
      },
      {
        path: "/appConfig",
        name: "appConfig",
        meta: { title: "APP配置" },
        component: () => import("../views/system/appConfig"),
      },

      {
        path: "/fcConfig",
        name: "fcConfig",
        meta: { title: "交易对配置" },
        component: () => import("../views/deal/fcConfig"),
      },
      {
        path: "/fcType",
        name: "fcType",
        meta: { title: "交易对类型" },
        component: () => import("../views/deal/fcType"),
      },
      {
        path: "/fcOrderUses",
        name: "fcOrderUses",
        meta: { title: "交易记录" },
        component: () => import("../views/deal/fcOrderUses"),
      },

      // 数字资产
      {
        path: "/daKind",
        name: "daKind",
        meta: { title: "数字资产种类" },
        component: () => import("../views/integral/daKind"),
      },
      {
        path: "/daConfig",
        name: "daConfig",
        meta: { title: "数字资产配置" },
        component: () => import("../views/integral/daConfig"),
      },
      {
        path: "/daLink",
        name: "daLink",
        meta: { title: "数字资产链信息" },
        component: () => import("../views/integral/daLink"),
      },
      {
        path: "/daChain",
        name: "daChain",
        meta: { title: "数字资产公链配置" },
        component: () => import("../views/integral/daChain"),
      },

      {
        path: "/cyBer",
        name: "cyBer",
        meta: { title: "资金明细" },
        component: () => import("../views/integral/fundDetails/cyBer"),
      },
      {
        path: "/recharge",
        name: "recharge",
        meta: { title: "资金充值审核" },
        component: () => import("../views/integral/fundDetails/fund"),
      },
      {
        path: "/withdraw",
        name: "withdraw",
        meta: { title: "资金提现审核" },
        component: () => import("../views/integral/fundDetails/withdraw"),
      },

      // 幸运大转盘
      {
        path: "/lotteryCommodity",
        name: "lotteryCommodity",
        meta: { title: "幸运大转盘商品" },
        component: () => import("../views/activity/lottery/commodity"),
      },
      {
        path: "/lotteryOrder",
        name: "lotteryOrder",
        meta: { title: "幸运大转盘订单" },
        component: () => import("../views/activity/lottery/order"),
      },
      // 盲盒
      {
        path: "/blindPartition",
        name: "blindPartition",
        meta: { title: "盲盒商品" },
        component: () => import("../views/activity/blind/partition"),
      },
      {
        path: "/blindCommodity",
        name: "blindCommodity",
        meta: { title: "盲盒商品" },
        component: () => import("../views/activity/blind/commodity"),
      },
      {
        path: "/blindOrder",
        name: "blindOrder",
        meta: { title: "盲盒订单" },
        component: () => import("../views/activity/blind/order"),
      },

      //自营商城
      {
        path: "/zyMallClass",
        name: "zyMallClass",
        meta: { title: "自营商城分类" },
        component: () => import("../views/zyMall/class"),
      },
      {
        path: "/zyMallCommodity",
        name: "zyMallCommodity",
        meta: { title: "自营商城商品" },
        component: () => import("../views/zyMall/commodity"),
      },
      {
        path: "/zyMallOrder",
        name: "zyMallOrder",
        meta: { title: "自营商城订单" },
        component: () => import("../views/zyMall/order"),
      },
      {
        path: "/zyMallPartition",
        name: "zyMallPartition",
        meta: { title: "自营分区" },
        component: () => import("../views/zyMall/partition"),
      },
      {
        path: "/zyMallRefund",
        name: "zyMallRefund",
        meta: { title: "自营退款" },
        component: () => import("../views/zyMall/refund"),
      },
      {
        path: "/selfPickingCard",
        name: "selfPickingCard",
        meta: { title: "自营分区" },
        component: () => import("../views/zyMall/selfPickingCard"),
      },

      {
        path: "/flashKillCommodity",
        name: "flashKillCommodity",
        meta: { title: "秒杀商品" },
        component: () => import("../views/activity/flashKill/commodity"),
      },
      {
        path: "/flashKillOrder",
        name: "flashKillOrder",
        meta: { title: "秒杀订单" },
        component: () => import("../views/activity/flashKill/order"),
      },

      {
        path: "/houseCommodity",
        name: "houseCommodity",
        meta: { title: "房产商品" },
        component: () => import("../views/house/commodity"),
      },
      {
        path: "/houseOrder",
        name: "houseOrder",
        meta: { title: "房产订单" },
        component: () => import("../views/house/order"),
      },
      {
        path: "/fitmentCommodity",
        name: "fitmentCommodity",
        meta: { title: "装修商品" },
        component: () => import("../views/fitment/commodity"),
      },
      {
        path: "/fitmentClass",
        name: "fitmentClass",
        meta: { title: "装修分类" },
        component: () => import("../views/fitment/class"),
      },
      {
        path: "/fitmentOrder",
        name: "fitmentOrder",
        meta: { title: "装修订单" },
        component: () => import("../views/fitment/order"),
      },



      {
        path: "/releaseConfig",
        name: "releaseConfig",
        meta: { title: "释放配置" },
        component: () => import("../views/release/config"),
      },
      {
        path: "/releaseOrder",
        name: "releaseOrder",
        meta: { title: "释放订单" },
        component: () => import("../views/release/order"),
      },
      {
        path: "/releaseRecord",
        name: "releaseRecord",
        meta: { title: "释放记录" },
        component: () => import("../views/release/record"),
      },

      //模型
      {
        path: "/icon",
        name: "icon",
        meta: { title: "自定义图标" },
        component: () => import("../views/Icon.vue"),
      },
      {
        path: "/404",
        name: "404",
        meta: { title: "找不到页面" },
        component: () => import("../views/404.vue"),
      },
      {
        path: "/403",
        name: "403",
        meta: { title: "没有权限" },
        component: () => import("../views/403.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    meta: { title: "登录" },
    component: () => import("../views/Login.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

router.beforeEach((to, from, next) => {
  document.title = ` 修好生活 | ${to.meta.title}`;
  const role = sessionStorage.getItem("Token");

  if (!role && to.path !== "/login") {
    next("/login");
  } else {
    next();
  }
});

export default router;
